from lib.pyse import Pyse
from faker import Faker
fake=Faker(locale='zh_CN')
class BasicPage(object):
    def __init__(self):
        self.pyse = Pyse('chrome')
    def open(self):
        self.pyse.open('http://172.20.20.7:7000/#/login')
    def quit(self):
        self.pyse.quit()

#查询微服务系统的登录
class LoginPage(BasicPage):
   def sendUsername(self):
       css = 'css=>input[placeholder="请输入用户名"]'
       self.pyse.type(css,'admin')
   def sendPasswd(self):
        css = 'css=>input[placeholder="请输入密码"]'
        self.pyse.type(css,'111111-a')
   def clickLogin(self):
        css = 'css=>button[class="el-button el-button--primary el-button--small"]'
        self.pyse.click(css)
   def checkLogin(self,name):
       css = 'css=>a[href="#"]'
       return self.pyse.wait_and_save_exception(css,name)

class Addrole(LoginPage):
    def roleButton(self):
        css = 'css=>i[class="icon DHCiconfont DHC-jiaoseguanli"]'
        self.pyse.click(css)
    def addButton(self):
        css = 'css=>button[class="el-button el-button--primary el-button--small is-plain"]'
        self.pyse.click(css)
    def roleName(self):
        css= 'xpath=>//div[@class="el-dialog__body"]/form[@class="el-form"]/div[0]/div[0]/div[0]/div[0]/div[0]/input[0]>'
        self.pyse.click(css,'rolename')
    def roleType(self):
        css = 'xpath=>//input[@class="el-input__inner"][5]'
        self.pyse.click()
        css = 'xpath=>//ul[@el-scrollbar__view el-select-dropdown__list][2]/li[0]'
        self.pyse.click()
    def roleDescription(self):
        css = 'css=>textarea[class="el-textarea__inner"]'
        self.pyse.type(css,'添加角色')


class Page(Addrole):
    pass

if __name__=='__main__':
    page = Page()
    page.open()
    page.sendUsername()
    page.sendPasswd()
    page.clickLogin()
    page.checkLogin(LoginPage)
    page.roleButton()
    page.addButton()
    page.roleName()
    page.roleType()
    page.roleDescription()
